package com.itheima.service.db.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.PmsProductCategoryAttributeRelation;
import com.itheima.mapper.PmsProductCategoryAttributeRelationMapper;
import com.itheima.service.db.PmsProductCategoryAttributeRelationService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class PmsProductCategoryAttributeRelationServiceImpl implements PmsProductCategoryAttributeRelationService {

    @Autowired
    PmsProductCategoryAttributeRelationMapper pmsProductCategoryAttributeRelationMapper;

    /**
     * //根据商品分类id查询商品属性id
     * @param productCategoryId
     * @return
     */
    @Override
    public List<Long> findAttributeId(Long productCategoryId) {
        //1.创造查询条件
        LambdaQueryWrapper<PmsProductCategoryAttributeRelation> qw = new LambdaQueryWrapper<>();
        qw.eq(PmsProductCategoryAttributeRelation::getProductCategoryId,productCategoryId);
        List<PmsProductCategoryAttributeRelation> pmsProductCategoryAttributeRelations = pmsProductCategoryAttributeRelationMapper.selectList(qw);

        List<Long> ids = new ArrayList<>();
        //2.遍历取得id
        if (CollUtil.isNotEmpty(pmsProductCategoryAttributeRelations)) {
            for (PmsProductCategoryAttributeRelation pmsProductCategoryAttributeRelation : pmsProductCategoryAttributeRelations) {
                ids.add(pmsProductCategoryAttributeRelation.getProductAttributeId());
            }
        }
        return ids;
    }
}
